﻿Namespace Imaging

    Public Structure RGBTriplet
        Public Red As Double
        Public Green As Double
        Public Blue As Double

        Public Sub New(ByVal Col As Drawing.Color)
            Red = Col.R / 255
            Green = Col.G / 255
            Blue = Col.B / 255
        End Sub

        Public Sub New(ByVal R As Double, ByVal G As Double, ByVal B As Double)
            Red = Math.Max(Math.Min(1, R), 0)
            Green = Math.Max(Math.Min(1, G), 0)
            Blue = Math.Max(Math.Min(1, B), 0)
        End Sub

        Public Overrides Function Equals(ByVal obj As Object) As Boolean
            Return (TypeOf (obj) Is RGBTriplet) AndAlso _
                   DirectCast(obj, RGBTriplet).Red = Me.Red AndAlso _
                   DirectCast(obj, RGBTriplet).Green = Me.Green AndAlso _
                   DirectCast(obj, RGBTriplet).Blue = Me.Blue
        End Function

        Public Overrides Function ToString() As String
            Return String.Format("#{0:X2}{1:X2}{2:X2}", Red * 255, Green * 255, Blue * 255)
        End Function

    End Structure

    Public Structure RGBEQuadlet
        Public Red As Byte
        Public Green As Byte
        Public Blue As Byte
        Public Exponent As Byte

        Public Sub New(ByVal r As Byte, ByVal g As Byte, ByVal b As Byte, ByVal e As Byte)
            Red = r
            Green = g
            Blue = b
            Exponent = e
        End Sub

    End Structure


    Public Structure XYZTriplet
        Public X As Double
        Public Y As Double
        Public Z As Double

        Public Sub New(ByVal NewX As Double, ByVal newY As Double, ByVal newZ As Double)
            X = NewX
            Y = newY
            Z = newZ
        End Sub
    End Structure

    Public Structure xyYTriplet
        Public x As Double
        Public y As Double
        Public XYZ_Y As Double

        Public Sub New(ByVal NewX As Double, ByVal newY As Double, ByVal newXYZ_Y As Double)
            x = NewX
            y = newY
            XYZ_Y = newXYZ_Y
        End Sub
    End Structure

    Public Structure LabTriplet
        Public Luminance As Double
        Public a As Double
        Public b As Double

        Public Sub New(ByVal NewL As Double, ByVal newA As Double, ByVal newB As Double)
            Luminance = NewL
            a = newA
            b = newB
        End Sub
    End Structure

    Public Structure LuvTriplet
        Public Luminance As Double
        Public u As Double
        Public v As Double

        Public Sub New(ByVal NewL As Double, ByVal newU As Double, ByVal newV As Double)
            Luminance = NewL
            u = newU
            v = newV
        End Sub
    End Structure

    Public Structure HSVTriplet
        Public Hue As Double
        Public Saturation As Double
        Public Value As Double

        Public Sub New(ByVal H As Double, ByVal S As Double, ByVal V As Double)
            Hue = H
            Saturation = S
            Value = V
        End Sub
    End Structure

End Namespace